<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2007-2008 Starbugs (univis2typo3@googlegroups.com)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Module: Web>UnivIS2Typo3
 *
 * Description:
 *
 * Notice: 
 *
 *  
 * @author	Starbugs <univis2typo3@googlegroups.com>
 */

require_once($BACK_PATH.'template.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.createTeamMember.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.editordertable.php');

class ConfigurationPersons
extends ConfigurationEditOrderTable
{
	var $content;
	var $template;
	var $teamMember;
	function renderContent($id)
	{
		$this->template = new Template();
		$this->teamMember = new CreateTeamMember();
		$content = '';
		$output = '';
		if ($_GET['name'])
		{
			ob_start();
			$this->teamMember->setPersonKey($_GET['name']);
			$this->teamMember->setOurTeamPageId($_GET['id']);
			$this->teamMember->create();
			$output = ob_get_contents();
			ob_end_clean();
			$content .= "
				<script type='text/javascript'>
					top.content.nav_frame.refresh_nav();
				</script>
		";

		}

		$content .= $this->template->header("Persons with NO personal page");

		$content .= "<p>To create a personal page for somebody just click the CREATE PAGE button next to their name.</p>";

		$this->template->table_TABLE = '<table border="1" cellspacing="0" cellpadding="3" id="typo3-tmpltable">';
		$content .= $this->template->table($this->getPersons($id));

		$content .= $_GET['name'];
		$content .= '<br />'.$output; 

		return $content;
	}

	function getPersons($id)
	{
		$selection	= "DISTINCT `u_person`.`key`, lastname, firstname, username";
		$from		= "`u_person_jobs` 
					JOIN `u_person` ON `u_person_jobs`.`per` =`u_person`.`key` 
					JOIN `u_job` ON `u_job`.`description` = `u_person_jobs`.`job_key`
					LEFT OUTER JOIN `be_users` ON `u_person`.`key` = `be_users`.`tx_univis2typo3_person_key`
					";
		$where 	= "ISNULL(username)";

		$groupby	= "";
		$orderby	= "`u_person`.`lastname`";
		$limit 		= "";

		$query = $GLOBALS['TYPO3_DB']->SELECTquery(
			$selection,   			// SELECT
			$from,				// FROM
			$where,				// WHERE
			$groupby,	    		// GROUP BY
			$orderby,			// ORDER BY
			$limit				// LIMIT
		);
		$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
		$out = array ();
	
		echo mysql_error();
		$out[] = array("<b>Lastname</b>", "<b>Firstname</b>", "&nbsp;");
		while ($row = mysql_fetch_assoc($res)) 
		{
			//$createLink = "<b><a href='?name=".$row['key']."&id=".$id."' style='background-color:black; color:white'>---CREATE PAGE---</a></b>";
			$createLink = $this->template->t3Button("document.location='?name=".$row['key']."&id=".$id."'","CREATE PAGE");
			$out[] = array($row['lastname'],$row['firstname'],$createLink);
		}		
				
		return $out;	
	}
}
?>
